{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "      detail_id  order_id  dishes_id  logicprn_name  parent_class_name  \\\n0          2956       417     610062            NaN                NaN   \n1          2958       417     609957            NaN                NaN   \n2          2961       417     609950            NaN                NaN   \n3          2966       417     610038            NaN                NaN   \n4          2968       417     610003            NaN                NaN   \n...         ...       ...        ...            ...                ...   \n2774       6750       774     610011            NaN                NaN   \n2775       6742       774     609996            NaN                NaN   \n2776       6756       774     609949            NaN                NaN   \n2777       6763       774     610014            NaN                NaN   \n2778       6764       774     610017            NaN                NaN   \n\n            dishes_name  itemis_add  counts  amounts  cost  \\\n0                  蒜蓉生蚝           0       1       49   NaN   \n1     蒙古烤羊腿\\r\\n\\r\\n\\r\\n           0       1       48   NaN   \n2                  大蒜苋菜           0       1       30   NaN   \n3                 芝麻烤紫菜           0       1       25   NaN   \n4                   蒜香包           0       1       13   NaN   \n...                 ...         ...     ...      ...   ...   \n2774              白饭/大碗           0       1       10   NaN   \n2775                牛尾汤           0       1       40   NaN   \n2776             意文柠檬汁            0       1       13   NaN   \n2777               金玉良缘           0       1       30   NaN   \n2778               酸辣藕丁           0       1       33   NaN   \n\n        place_order_time  discount_amt  discount_reason  kick_back  \\\n0    2016-08-01 11:05:36           NaN              NaN        NaN   \n1    2016-08-01 11:07:07           NaN              NaN        NaN   \n2    2016-08-01 11:07:40           NaN              NaN        NaN   \n3    2016-08-01 11:11:11           NaN              NaN        NaN   \n4    2016-08-01 11:11:30           NaN              NaN        NaN   \n...                  ...           ...              ...        ...   \n2774 2016-08-10 21:56:24           NaN              NaN        NaN   \n2775 2016-08-10 21:56:48           NaN              NaN        NaN   \n2776 2016-08-10 22:01:52           NaN              NaN        NaN   \n2777 2016-08-10 22:03:58           NaN              NaN        NaN   \n2778 2016-08-10 22:04:30           NaN              NaN        NaN   \n\n      add_inprice  add_info  bar_code      picture_file  emp_id  \n0               0       NaN       NaN  caipu/104001.jpg    1442  \n1               0       NaN       NaN  caipu/202003.jpg    1442  \n2               0       NaN       NaN  caipu/303001.jpg    1442  \n3               0       NaN       NaN  caipu/105002.jpg    1442  \n4               0       NaN       NaN  caipu/503002.jpg    1442  \n...           ...       ...       ...               ...     ...  \n2774            0       NaN       NaN  caipu/601005.jpg    1138  \n2775            0       NaN       NaN  caipu/201006.jpg    1138  \n2776            0       NaN       NaN  caipu/404005.jpg    1138  \n2777            0       NaN       NaN  caipu/302003.jpg    1138  \n2778            0       NaN       NaN  caipu/302006.jpg    1138  \n\n[2779 rows x 19 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>detail_id</th>\n      <th>order_id</th>\n      <th>dishes_id</th>\n      <th>logicprn_name</th>\n      <th>parent_class_name</th>\n      <th>dishes_name</th>\n      <th>itemis_add</th>\n      <th>counts</th>\n      <th>amounts</th>\n      <th>cost</th>\n      <th>place_order_time</th>\n      <th>discount_amt</th>\n      <th>discount_reason</th>\n      <th>kick_back</th>\n      <th>add_inprice</th>\n      <th>add_info</th>\n      <th>bar_code</th>\n      <th>picture_file</th>\n      <th>emp_id</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2956</td>\n      <td>417</td>\n      <td>610062</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>蒜蓉生蚝</td>\n      <td>0</td>\n      <td>1</td>\n      <td>49</td>\n      <td>NaN</td>\n      <td>2016-08-01 11:05:36</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>caipu/104001.jpg</td>\n      <td>1442</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2958</td>\n      <td>417</td>\n      <td>609957</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>蒙古烤羊腿\\r\\n\\r\\n\\r\\n</td>\n      <td>0</td>\n      <td>1</td>\n      <td>48</td>\n      <td>NaN</td>\n      <td>2016-08-01 11:07:07</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>caipu/202003.jpg</td>\n      <td>1442</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2961</td>\n      <td>417</td>\n      <td>609950</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>大蒜苋菜</td>\n      <td>0</td>\n      <td>1</td>\n      <td>30</td>\n      <td>NaN</td>\n      <td>2016-08-01 11:07:40</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>caipu/303001.jpg</td>\n      <td>1442</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2966</td>\n      <td>417</td>\n      <td>610038</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>芝麻烤紫菜</td>\n      <td>0</td>\n      <td>1</td>\n      <td>25</td>\n      <td>NaN</td>\n      <td>2016-08-01 11:11:11</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>caipu/105002.jpg</td>\n      <td>1442</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2968</td>\n      <td>417</td>\n      <td>610003</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>蒜香包</td>\n      <td>0</td>\n      <td>1</td>\n      <td>13</td>\n      <td>NaN</td>\n      <td>2016-08-01 11:11:30</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>caipu/503002.jpg</td>\n      <td>1442</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>2774</th>\n      <td>6750</td>\n      <td>774</td>\n      <td>610011</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>白饭/大碗</td>\n      <td>0</td>\n      <td>1</td>\n      <td>10</td>\n      <td>NaN</td>\n      <td>2016-08-10 21:56:24</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>caipu/601005.jpg</td>\n      <td>1138</td>\n    </tr>\n    <tr>\n      <th>2775</th>\n      <td>6742</td>\n      <td>774</td>\n      <td>609996</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>牛尾汤</td>\n      <td>0</td>\n      <td>1</td>\n      <td>40</td>\n      <td>NaN</td>\n      <td>2016-08-10 21:56:48</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>caipu/201006.jpg</td>\n      <td>1138</td>\n    </tr>\n    <tr>\n      <th>2776</th>\n      <td>6756</td>\n      <td>774</td>\n      <td>609949</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>意文柠檬汁</td>\n      <td>0</td>\n      <td>1</td>\n      <td>13</td>\n      <td>NaN</td>\n      <td>2016-08-10 22:01:52</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>caipu/404005.jpg</td>\n      <td>1138</td>\n    </tr>\n    <tr>\n      <th>2777</th>\n      <td>6763</td>\n      <td>774</td>\n      <td>610014</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>金玉良缘</td>\n      <td>0</td>\n      <td>1</td>\n      <td>30</td>\n      <td>NaN</td>\n      <td>2016-08-10 22:03:58</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>caipu/302003.jpg</td>\n      <td>1138</td>\n    </tr>\n    <tr>\n      <th>2778</th>\n      <td>6764</td>\n      <td>774</td>\n      <td>610017</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>酸辣藕丁</td>\n      <td>0</td>\n      <td>1</td>\n      <td>33</td>\n      <td>NaN</td>\n      <td>2016-08-10 22:04:30</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>caipu/302006.jpg</td>\n      <td>1138</td>\n    </tr>\n  </tbody>\n</table>\n<p>2779 rows × 19 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 2
    }
   ],
   "source": [
    "detail1=pd.read_excel('./meal_order_detail.xlsx','meal_order_detail1')\n",
    "detail1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "      counts   amounts\n0        0.0  0.271186\n1        0.0  0.265537\n2        0.0  0.163842\n3        0.0  0.135593\n4        0.0  0.067797\n...      ...       ...\n2774     0.0  0.050847\n2775     0.0  0.220339\n2776     0.0  0.067797\n2777     0.0  0.163842\n2778     0.0  0.180791\n\n[2779 rows x 2 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>counts</th>\n      <th>amounts</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0.0</td>\n      <td>0.271186</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>0.0</td>\n      <td>0.265537</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0.0</td>\n      <td>0.163842</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>0.0</td>\n      <td>0.135593</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>0.0</td>\n      <td>0.067797</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>2774</th>\n      <td>0.0</td>\n      <td>0.050847</td>\n    </tr>\n    <tr>\n      <th>2775</th>\n      <td>0.0</td>\n      <td>0.220339</td>\n    </tr>\n    <tr>\n      <th>2776</th>\n      <td>0.0</td>\n      <td>0.067797</td>\n    </tr>\n    <tr>\n      <th>2777</th>\n      <td>0.0</td>\n      <td>0.163842</td>\n    </tr>\n    <tr>\n      <th>2778</th>\n      <td>0.0</td>\n      <td>0.180791</td>\n    </tr>\n  </tbody>\n</table>\n<p>2779 rows × 2 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 3
    }
   ],
   "source": [
    "# 最大最小标准化\n",
    "def MinMaxScale(data):\n",
    "    return (data-data.min())/(data.max()-data.min())\n",
    "a=MinMaxScale(detail1['counts'])\n",
    "b=MinMaxScale(detail1['amounts'])\n",
    "pd.concat([a,b],axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 标准化数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "        counts   amounts\n0    -0.177784  0.099510\n1    -0.177784  0.072343\n2    -0.177784 -0.416674\n3    -0.177784 -0.552512\n4    -0.177784 -0.878523\n...        ...       ...\n2774 -0.177784 -0.960026\n2775 -0.177784 -0.144998\n2776 -0.177784 -0.878523\n2777 -0.177784 -0.416674\n2778 -0.177784 -0.335171\n\n[2779 rows x 2 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>counts</th>\n      <th>amounts</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>-0.177784</td>\n      <td>0.099510</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>-0.177784</td>\n      <td>0.072343</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>-0.177784</td>\n      <td>-0.416674</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>-0.177784</td>\n      <td>-0.552512</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>-0.177784</td>\n      <td>-0.878523</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>2774</th>\n      <td>-0.177784</td>\n      <td>-0.960026</td>\n    </tr>\n    <tr>\n      <th>2775</th>\n      <td>-0.177784</td>\n      <td>-0.144998</td>\n    </tr>\n    <tr>\n      <th>2776</th>\n      <td>-0.177784</td>\n      <td>-0.878523</td>\n    </tr>\n    <tr>\n      <th>2777</th>\n      <td>-0.177784</td>\n      <td>-0.416674</td>\n    </tr>\n    <tr>\n      <th>2778</th>\n      <td>-0.177784</td>\n      <td>-0.335171</td>\n    </tr>\n  </tbody>\n</table>\n<p>2779 rows × 2 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 4
    }
   ],
   "source": [
    "# Z-Score（标准差）标准化\n",
    "def StandardScale(data):\n",
    "    return (data-data.mean())/data.std()\n",
    "a=StandardScale(detail1['counts'])\n",
    "b=StandardScale(detail1['amounts'])\n",
    "pd.concat([a,b],axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "      counts  amounts\n0        0.1    0.049\n1        0.1    0.048\n2        0.1    0.030\n3        0.1    0.025\n4        0.1    0.013\n...      ...      ...\n2774     0.1    0.010\n2775     0.1    0.040\n2776     0.1    0.013\n2777     0.1    0.030\n2778     0.1    0.033\n\n[2779 rows x 2 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>counts</th>\n      <th>amounts</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0.1</td>\n      <td>0.049</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>0.1</td>\n      <td>0.048</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0.1</td>\n      <td>0.030</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>0.1</td>\n      <td>0.025</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>0.1</td>\n      <td>0.013</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>2774</th>\n      <td>0.1</td>\n      <td>0.010</td>\n    </tr>\n    <tr>\n      <th>2775</th>\n      <td>0.1</td>\n      <td>0.040</td>\n    </tr>\n    <tr>\n      <th>2776</th>\n      <td>0.1</td>\n      <td>0.013</td>\n    </tr>\n    <tr>\n      <th>2777</th>\n      <td>0.1</td>\n      <td>0.030</td>\n    </tr>\n    <tr>\n      <th>2778</th>\n      <td>0.1</td>\n      <td>0.033</td>\n    </tr>\n  </tbody>\n</table>\n<p>2779 rows × 2 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 5
    }
   ],
   "source": [
    "# 小数定标标准化\n",
    "def DecimalScale(data):\n",
    "    return data/10**(np.ceil(np.log10(data.abs().max())))\n",
    "a=DecimalScale(detail1['counts'])\n",
    "b=DecimalScale(detail1['amounts'])\n",
    "pd.concat([a,b],axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "      counts   amounts\n0        0.0  1.690196\n1        0.0  1.681241\n2        0.0  1.477121\n3        0.0  1.397940\n4        0.0  1.113943\n...      ...       ...\n2774     0.0  1.000000\n2775     0.0  1.602060\n2776     0.0  1.113943\n2777     0.0  1.477121\n2778     0.0  1.518514\n\n[2779 rows x 2 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>counts</th>\n      <th>amounts</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>0.0</td>\n      <td>1.690196</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>0.0</td>\n      <td>1.681241</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0.0</td>\n      <td>1.477121</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>0.0</td>\n      <td>1.397940</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>0.0</td>\n      <td>1.113943</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>2774</th>\n      <td>0.0</td>\n      <td>1.000000</td>\n    </tr>\n    <tr>\n      <th>2775</th>\n      <td>0.0</td>\n      <td>1.602060</td>\n    </tr>\n    <tr>\n      <th>2776</th>\n      <td>0.0</td>\n      <td>1.113943</td>\n    </tr>\n    <tr>\n      <th>2777</th>\n      <td>0.0</td>\n      <td>1.477121</td>\n    </tr>\n    <tr>\n      <th>2778</th>\n      <td>0.0</td>\n      <td>1.518514</td>\n    </tr>\n  </tbody>\n</table>\n<p>2779 rows × 2 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 6
    }
   ],
   "source": [
    "# Log变换\n",
    "def LogScale(data):\n",
    "    return np.log10(data)\n",
    "a=LogScale(detail1['counts'])\n",
    "b=LogScale(detail1['amounts'])\n",
    "pd.concat([a,b],axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "array([[0.        , 0.27118644],\n       [0.        , 0.26553672],\n       [0.        , 0.16384181],\n       ...,\n       [0.        , 0.06779661],\n       [0.        , 0.16384181],\n       [0.        , 0.18079096]])"
     },
     "metadata": {},
     "execution_count": 7
    }
   ],
   "source": [
    "from sklearn import preprocessing\n",
    "\n",
    "min_max_scaler=preprocessing.MinMaxScaler()\n",
    "min_max_scaler.fit_transform(detail1[['counts','amounts']])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "array([[0.11111111, 0.16384181]])"
     },
     "metadata": {},
     "execution_count": 8
    }
   ],
   "source": [
    "min_max_scaler=preprocessing.MinMaxScaler()\n",
    "min_max_scaler=min_max_scaler.fit(detail1[['counts','amounts']])\n",
    "min_max_scaler.transform([[2,30]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "array([[-0.17781606,  0.09952817],\n       [-0.17781606,  0.07235568],\n       [-0.17781606, -0.41674915],\n       ...,\n       [-0.17781606, -0.87868148],\n       [-0.17781606, -0.41674915],\n       [-0.17781606, -0.33523168]])"
     },
     "metadata": {},
     "execution_count": 9
    }
   ],
   "source": [
    "standard_scaler=preprocessing.StandardScaler()\n",
    "standard_scaler.fit_transform(detail1[['counts','amounts']])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "       工号  姓名          日期           时段     交易额    柜台\n0    1001  张三  2019-03-01   9：00-14：00  1664.0   化妆品\n1    1002  李四  2019-03-01  14：00-21：00   954.0   化妆品\n2    1003  王五  2019-03-01   9：00-14：00  1407.0    食品\n3    1004  赵六  2019-03-01  14：00-21：00  1320.0    食品\n4    1005  周七  2019-03-01   9：00-14：00   994.0   日用品\n..    ...  ..         ...          ...     ...   ...\n244  1002  李四  2019-03-31  14：00-21：00   859.0  蔬菜水果\n245  1004  赵六  2019-03-31   9：00-14：00  1668.0   日用品\n246  1004  赵六  2019-03-31  14：00-21：00  1722.0   日用品\n247  1003  王五  2019-03-31   9：00-14：00  1274.0    食品\n248  1006  钱八  2019-03-31  14：00-21：00   812.0    食品\n\n[249 rows x 6 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>工号</th>\n      <th>姓名</th>\n      <th>日期</th>\n      <th>时段</th>\n      <th>交易额</th>\n      <th>柜台</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-01</td>\n      <td>9：00-14：00</td>\n      <td>1664.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-01</td>\n      <td>14：00-21：00</td>\n      <td>954.0</td>\n      <td>化妆品</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-01</td>\n      <td>9：00-14：00</td>\n      <td>1407.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-01</td>\n      <td>14：00-21：00</td>\n      <td>1320.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-01</td>\n      <td>9：00-14：00</td>\n      <td>994.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>244</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-31</td>\n      <td>14：00-21：00</td>\n      <td>859.0</td>\n      <td>蔬菜水果</td>\n    </tr>\n    <tr>\n      <th>245</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-31</td>\n      <td>9：00-14：00</td>\n      <td>1668.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>246</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-31</td>\n      <td>14：00-21：00</td>\n      <td>1722.0</td>\n      <td>日用品</td>\n    </tr>\n    <tr>\n      <th>247</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-31</td>\n      <td>9：00-14：00</td>\n      <td>1274.0</td>\n      <td>食品</td>\n    </tr>\n    <tr>\n      <th>248</th>\n      <td>1006</td>\n      <td>钱八</td>\n      <td>2019-03-31</td>\n      <td>14：00-21：00</td>\n      <td>812.0</td>\n      <td>食品</td>\n    </tr>\n  </tbody>\n</table>\n<p>249 rows × 6 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 10
    }
   ],
   "source": [
    "sales=pd.read_excel('./超市营业额2.xlsx')\n",
    "sales"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "array(['化妆品', '食品', '日用品', '蔬菜水果'], dtype=object)"
     },
     "metadata": {},
     "execution_count": 11
    }
   ],
   "source": [
    "sales['柜台'].unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "蔬菜水果    63\n日用品     62\n化妆品     62\n食品      62\nName: 柜台, dtype: int64"
     },
     "metadata": {},
     "execution_count": 12
    }
   ],
   "source": [
    "sales['柜台'].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 数值映射"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 第一种方法\n",
    "sales=pd.read_excel('./超市营业额2.xlsx')\n",
    "sales['柜台'].replace(['化妆品', '食品', '日用品', '蔬菜水果'],range(4),inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "       工号  姓名          日期           时段     交易额  柜台\n0    1001  张三  2019-03-01   9：00-14：00  1664.0   0\n1    1002  李四  2019-03-01  14：00-21：00   954.0   0\n2    1003  王五  2019-03-01   9：00-14：00  1407.0   1\n3    1004  赵六  2019-03-01  14：00-21：00  1320.0   1\n4    1005  周七  2019-03-01   9：00-14：00   994.0   2\n..    ...  ..         ...          ...     ...  ..\n244  1002  李四  2019-03-31  14：00-21：00   859.0   3\n245  1004  赵六  2019-03-31   9：00-14：00  1668.0   2\n246  1004  赵六  2019-03-31  14：00-21：00  1722.0   2\n247  1003  王五  2019-03-31   9：00-14：00  1274.0   1\n248  1006  钱八  2019-03-31  14：00-21：00   812.0   1\n\n[249 rows x 6 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>工号</th>\n      <th>姓名</th>\n      <th>日期</th>\n      <th>时段</th>\n      <th>交易额</th>\n      <th>柜台</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-01</td>\n      <td>9：00-14：00</td>\n      <td>1664.0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-01</td>\n      <td>14：00-21：00</td>\n      <td>954.0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-01</td>\n      <td>9：00-14：00</td>\n      <td>1407.0</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-01</td>\n      <td>14：00-21：00</td>\n      <td>1320.0</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-01</td>\n      <td>9：00-14：00</td>\n      <td>994.0</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>244</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-31</td>\n      <td>14：00-21：00</td>\n      <td>859.0</td>\n      <td>3</td>\n    </tr>\n    <tr>\n      <th>245</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-31</td>\n      <td>9：00-14：00</td>\n      <td>1668.0</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>246</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-31</td>\n      <td>14：00-21：00</td>\n      <td>1722.0</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>247</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-31</td>\n      <td>9：00-14：00</td>\n      <td>1274.0</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>248</th>\n      <td>1006</td>\n      <td>钱八</td>\n      <td>2019-03-31</td>\n      <td>14：00-21：00</td>\n      <td>812.0</td>\n      <td>1</td>\n    </tr>\n  </tbody>\n</table>\n<p>249 rows × 6 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 14
    }
   ],
   "source": [
    "# 第二种方法\n",
    "sales=pd.read_excel('./超市营业额2.xlsx')\n",
    "sales['柜台']=sales['柜台'].map({'化妆品':0,'食品':1,'日用品':2,'蔬菜水果':3})\n",
    "sales"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "[0 0 1 1 2 2 3 3 0 0 1 1 2 2 3 3 0 0 1 1 2 2 3 3 0 0 1 1 2 2 3 3 0 0 1 1 2\n 2 3 3 0 0 1 1 2 2 3 3 0 0 1 1 2 2 3 3 0 0 1 1 2 2 3 3 0 0 1 1 2 2 3 3 0 0\n 1 1 2 2 3 3 2 2 1 1 0 0 3 3 2 2 1 1 0 0 3 3 2 2 1 1 0 0 3 3 3 2 2 1 1 0 0\n 3 3 2 2 1 1 0 0 3 3 2 2 1 1 0 0 3 3 2 2 3 3 0 0 1 1 0 0 3 3 2 2 1 1 0 0 3\n 3 2 2 1 1 0 0 3 3 2 2 1 1 0 0 3 3 2 2 1 1 0 0 3 3 2 2 1 1 0 0 3 3 2 2 1 1\n 0 0 3 3 2 2 1 1 0 0 3 3 2 2 1 1 0 0 3 3 2 2 1 1 0 0 3 3 2 2 1 1 0 0 3 3 2\n 2 1 1 0 0 3 3 2 2 1 1 0 0 3 3 2 2 1 1 0 0 3 3 2 2 1 1]\nIndex(['化妆品', '食品', '日用品', '蔬菜水果'], dtype='object')\n"
    },
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "       工号  姓名          日期           时段     交易额  柜台\n0    1001  张三  2019-03-01   9：00-14：00  1664.0   0\n1    1002  李四  2019-03-01  14：00-21：00   954.0   0\n2    1003  王五  2019-03-01   9：00-14：00  1407.0   1\n3    1004  赵六  2019-03-01  14：00-21：00  1320.0   1\n4    1005  周七  2019-03-01   9：00-14：00   994.0   2\n..    ...  ..         ...          ...     ...  ..\n244  1002  李四  2019-03-31  14：00-21：00   859.0   3\n245  1004  赵六  2019-03-31   9：00-14：00  1668.0   2\n246  1004  赵六  2019-03-31  14：00-21：00  1722.0   2\n247  1003  王五  2019-03-31   9：00-14：00  1274.0   1\n248  1006  钱八  2019-03-31  14：00-21：00   812.0   1\n\n[249 rows x 6 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>工号</th>\n      <th>姓名</th>\n      <th>日期</th>\n      <th>时段</th>\n      <th>交易额</th>\n      <th>柜台</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-01</td>\n      <td>9：00-14：00</td>\n      <td>1664.0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-01</td>\n      <td>14：00-21：00</td>\n      <td>954.0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-01</td>\n      <td>9：00-14：00</td>\n      <td>1407.0</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-01</td>\n      <td>14：00-21：00</td>\n      <td>1320.0</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-01</td>\n      <td>9：00-14：00</td>\n      <td>994.0</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>244</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-31</td>\n      <td>14：00-21：00</td>\n      <td>859.0</td>\n      <td>3</td>\n    </tr>\n    <tr>\n      <th>245</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-31</td>\n      <td>9：00-14：00</td>\n      <td>1668.0</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>246</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-31</td>\n      <td>14：00-21：00</td>\n      <td>1722.0</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>247</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-31</td>\n      <td>9：00-14：00</td>\n      <td>1274.0</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>248</th>\n      <td>1006</td>\n      <td>钱八</td>\n      <td>2019-03-31</td>\n      <td>14：00-21：00</td>\n      <td>812.0</td>\n      <td>1</td>\n    </tr>\n  </tbody>\n</table>\n<p>249 rows × 6 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 15
    }
   ],
   "source": [
    "# 第三种方法\n",
    "sales=pd.read_excel('./超市营业额2.xlsx')\n",
    "labels,uniques=pd.factorize(sales['柜台'])\n",
    "print(labels)\n",
    "print(uniques)\n",
    "\n",
    "sales['柜台']=labels\n",
    "sales"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "       工号  姓名          日期           时段     交易额  柜台\n0    1001  张三  2019-03-01   9：00-14：00  1664.0   0\n1    1002  李四  2019-03-01  14：00-21：00   954.0   0\n2    1003  王五  2019-03-01   9：00-14：00  1407.0   3\n3    1004  赵六  2019-03-01  14：00-21：00  1320.0   3\n4    1005  周七  2019-03-01   9：00-14：00   994.0   1\n..    ...  ..         ...          ...     ...  ..\n244  1002  李四  2019-03-31  14：00-21：00   859.0   2\n245  1004  赵六  2019-03-31   9：00-14：00  1668.0   1\n246  1004  赵六  2019-03-31  14：00-21：00  1722.0   1\n247  1003  王五  2019-03-31   9：00-14：00  1274.0   3\n248  1006  钱八  2019-03-31  14：00-21：00   812.0   3\n\n[249 rows x 6 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>工号</th>\n      <th>姓名</th>\n      <th>日期</th>\n      <th>时段</th>\n      <th>交易额</th>\n      <th>柜台</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1001</td>\n      <td>张三</td>\n      <td>2019-03-01</td>\n      <td>9：00-14：00</td>\n      <td>1664.0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-01</td>\n      <td>14：00-21：00</td>\n      <td>954.0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-01</td>\n      <td>9：00-14：00</td>\n      <td>1407.0</td>\n      <td>3</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-01</td>\n      <td>14：00-21：00</td>\n      <td>1320.0</td>\n      <td>3</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>1005</td>\n      <td>周七</td>\n      <td>2019-03-01</td>\n      <td>9：00-14：00</td>\n      <td>994.0</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>244</th>\n      <td>1002</td>\n      <td>李四</td>\n      <td>2019-03-31</td>\n      <td>14：00-21：00</td>\n      <td>859.0</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>245</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-31</td>\n      <td>9：00-14：00</td>\n      <td>1668.0</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>246</th>\n      <td>1004</td>\n      <td>赵六</td>\n      <td>2019-03-31</td>\n      <td>14：00-21：00</td>\n      <td>1722.0</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>247</th>\n      <td>1003</td>\n      <td>王五</td>\n      <td>2019-03-31</td>\n      <td>9：00-14：00</td>\n      <td>1274.0</td>\n      <td>3</td>\n    </tr>\n    <tr>\n      <th>248</th>\n      <td>1006</td>\n      <td>钱八</td>\n      <td>2019-03-31</td>\n      <td>14：00-21：00</td>\n      <td>812.0</td>\n      <td>3</td>\n    </tr>\n  </tbody>\n</table>\n<p>249 rows × 6 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 16
    }
   ],
   "source": [
    "# 第四种方法\n",
    "sales=pd.read_excel('./超市营业额2.xlsx')\n",
    "label_encoder=preprocessing.LabelEncoder()\n",
    "sales['柜台']=label_encoder.fit_transform(sales['柜台'])\n",
    "sales"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "     化妆品  日用品  蔬菜水果  食品\n0      1    0     0   0\n1      1    0     0   0\n2      0    0     0   1\n3      0    0     0   1\n4      0    1     0   0\n..   ...  ...   ...  ..\n244    0    0     1   0\n245    0    1     0   0\n246    0    1     0   0\n247    0    0     0   1\n248    0    0     0   1\n\n[249 rows x 4 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>化妆品</th>\n      <th>日用品</th>\n      <th>蔬菜水果</th>\n      <th>食品</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>244</th>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>245</th>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>246</th>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>247</th>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>248</th>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n    </tr>\n  </tbody>\n</table>\n<p>249 rows × 4 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 17
    }
   ],
   "source": [
    "sales=pd.read_excel('./超市营业额2.xlsx')\n",
    "pd.get_dummies(sales['柜台'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "<249x4 sparse matrix of type '<class 'numpy.float64'>'\n\twith 249 stored elements in Compressed Sparse Row format>"
     },
     "metadata": {},
     "execution_count": 18
    }
   ],
   "source": [
    "one_hot_encoder=preprocessing.OneHotEncoder(categories='auto')\n",
    "one_hot_encoder.fit_transform(pd.DataFrame(sales['柜台']))"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "version": "3.7.7-final"
  },
  "orig_nbformat": 2,
  "file_extension": ".py",
  "mimetype": "text/x-python",
  "name": "python",
  "npconvert_exporter": "python",
  "pygments_lexer": "ipython3",
  "version": 3,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}